//
//  HATabBarViewController.m
//  HA
//
//  Created by sy on 2023/12/17.
//

#import "HATabBarViewController.h"
#import "HANavViewController.h"
#import "HAHomeVC.h"
#import "HAYJVC.h"
#import "HAMEVC.h"
#import "HAWebVC.h"

//#import "HAPredationVC.h"
//#import "HAAllMerchantVC.h"
//#import "HAMachineVC.h"
//#import "HATransactionLookVC.h"

@interface HATabBarViewController ()<UITabBarDelegate,UITabBarControllerDelegate>

@end

@implementation HATabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    
    HAHomeVC *v1 = [[HAHomeVC alloc] init];
    HAYJVC *v2 = [[HAYJVC alloc]init];
    HAMEVC *v3 = [[HAMEVC alloc] init];
    HANavViewController *n1 = [[HANavViewController alloc] initWithRootViewController:v1];
    HANavViewController *n2 = [[HANavViewController alloc] initWithRootViewController:v2];
    HANavViewController *n3 = [[HANavViewController alloc] initWithRootViewController:v3];


    NSArray *icons_normal;
    NSArray *icons_selected;
    NSArray *titles;
    
    self.viewControllers = @[n1, n2, n3];
    icons_normal = @[@"tab_n_0",@"tab_n_2",@"tab_n_3"];
    icons_selected = @[@"tab_s_0",@"tab_s_2",@"tab_s_3"];
    titles = @[@"首页",@"展业中心",@"我的"];

    self.delegate = self;

    self.tabBar.itemPositioning = UITabBarItemPositioningCentered;
    [[UITabBar appearance] setTintColor:[UIColor colorWithHexString:@"#E36A5F"]];
    
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *item, NSUInteger idx, BOOL *stop) {
        item.image = [[UIImage imageNamed:icons_normal[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [[UIImage imageNamed:icons_selected[idx]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.title = titles[idx];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#282B2D"]} forState:UIControlStateNormal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#E36A5F"]} forState:UIControlStateSelected];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor clearColor]} forState:UIControlStateSelected];
        if (idx == 0) {
            item.imageInsets = UIEdgeInsetsMake(8, 0, -8, 0);
        }else {
            item.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        }
    }];
    

    [self productChannelComplete];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handMyApns:) name:@"YHTAPNSNotification" object:nil];

    // Do any additional setup after loading the view.
}

-(void)productChannelComplete {
    [HAHelper productChannelComplete:^(NSArray * _Nonnull array) {
    }];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

    return YES;
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    [self.tabBar.items enumerateObjectsUsingBlock:^(UITabBarItem *item, NSUInteger idx, BOOL *stop) {
        item.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    }];
    item.imageInsets = UIEdgeInsetsMake(8, 0, -8, 0);
}

//-(void)handMyApns: (NSNotification*)noti {
//    
//    if (HAUserDefaults.isLock == 1) {
//        return;
//    }
//    
//    NSDictionary *userInfo = [noti object];
//    
//    if ([[userInfo allKeys]containsObject:@"_j_data_"]) {
//        NSData *jsonData = [[userInfo valueForKey:@"_j_data_"] dataUsingEncoding:NSUTF8StringEncoding];
//        NSError *err;
//        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
//                                                            options:NSJSONReadingMutableContainers
//                                                              error:&err];
//        if(!err)
//        {
//            if ([[dic allKeys]containsObject:@"push_type"]) {
//                NSInteger push_type = [[dic valueForKey:@"push_type"] integerValue];
//                if (push_type == 1) {
//                    HAPredationVC *vc = [[HAPredationVC alloc]init];
//                    [[HAHelper getCurrentVc].navigationController pushViewController:vc animated:YES];
//                }else if (push_type == 2) {
//                    HAAllMerchantVC *vc = [[HAAllMerchantVC alloc]init];
//                    [[HAHelper getCurrentVc].navigationController pushViewController:vc animated:YES];
//                }else if (push_type == 3) {
//                    HAMachineVC *vc = [[HAMachineVC alloc]init];
//                    [[HAHelper getCurrentVc].navigationController pushViewController:vc animated:YES];
//                }else if (push_type == 4) {
//                    HATransactionLookVC *vc = [[HATransactionLookVC alloc]init];
//                    [[HAHelper getCurrentVc].navigationController pushViewController:vc animated:YES];
//                }else if (push_type == 5) {
//                    if ([HAHelper getCurrentVc].navigationController.viewControllers.count > 1) {
//                        [[HAHelper getCurrentVc].navigationController popViewControllerAnimated:YES];
//                    }
//                    self.selectedIndex = 2;
//                }
//            }
//        }
//    }
//}




@end
